<template>
    <div id="app">
        <!-- {{ $store.state.name }} -->
        <!-- {{ name }}
        {{ newName }} -->
        {{ newName3 }}
        {{ $store.state.obj }}
        <br />
        <!-- <button @click="setNameFn">setName</button> -->
        <button @click="setNameFn1">setNameFn1</button>
        <button @click="setNameFn2">setNameFn2</button>
        <button @click="setObj">setObj</button>
    </div>
</template>

<script>
import { mapState, mapActions, mapMutations } from "vuex";
export default {
    name: "App",
    components: {},
    data() {
        return {
            name: "我是大飞",
            // obj: {
            //     name: "",
            // },
        };
    },
    computed: {
        // ...mapState(["name"]),
        ...mapState({
            newName: "name", //  key-value key我们要修改的名字 value是vuex中state的值
            newName2: (state) => {
                // state -> $store中的state
                return state.name;
            },
            newName3: (state) => state.name,
        }),
    },
    methods: {
        // ...mapActions(["setName"]),
        ...mapActions({
            setNameFn1: "setName",
        }),
        ...mapMutations({
            setNameFn2: "setName",
            setObj: "setObj",
        }),
        setNameFn() {
            // dispatch -> 调用actions
            // commit -> 调用mutations
            const res = this.$store.commit("setName");
            console.log(res);
            // const res = this.setName();
            // res.then((data) => console.log(data));
        },
    },
};
</script>

<style>
#app {
    font-family: Avenir, Helvetica, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-align: center;
    color: #2c3e50;
    margin-top: 60px;
}
</style>
